// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

pub mod firestore {
    use crate::Result;

    /// A builder for [Firestore][crate::client::Firestore].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_firestore::*;
    /// # use builder::firestore::ClientBuilder;
    /// # use client::Firestore;
    /// let builder : ClientBuilder = Firestore::builder();
    /// let client = builder
    ///     .with_endpoint("https://firestore.googleapis.com")
    ///     .build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub type ClientBuilder =
        gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;

    pub(crate) mod client {
        use super::super::super::client::Firestore;
        pub struct Factory;
        impl gax::client_builder::internal::ClientFactory for Factory {
            type Client = Firestore;
            type Credentials = gaxi::options::Credentials;
            async fn build(
                self,
                config: gaxi::options::ClientConfig,
            ) -> gax::client_builder::Result<Self::Client> {
                Self::Client::new(config).await
            }
        }
    }

    /// Common implementation for [crate::client::Firestore] request builders.
    #[derive(Clone, Debug)]
    pub(crate) struct RequestBuilder<R: std::default::Default> {
        stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        request: R,
        options: gax::options::RequestOptions,
    }

    impl<R> RequestBuilder<R>
    where
        R: std::default::Default,
    {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self {
                stub,
                request: R::default(),
                options: gax::options::RequestOptions::default(),
            }
        }
    }

    /// The request builder for [Firestore::get_document][crate::client::Firestore::get_document] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::GetDocument;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> GetDocument {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct GetDocument(RequestBuilder<crate::model::GetDocumentRequest>);

    impl GetDocument {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::GetDocumentRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::Document> {
            (*self.0.stub)
                .get_document(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [name][crate::model::GetDocumentRequest::name].
        ///
        /// This is a **required** field for requests.
        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.name = v.into();
            self
        }

        /// Sets the value of [mask][crate::model::GetDocumentRequest::mask].
        pub fn set_mask<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.mask = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [mask][crate::model::GetDocumentRequest::mask].
        pub fn set_or_clear_mask<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.mask = v.map(|x| x.into());
            self
        }

        /// Sets the value of [consistency_selector][crate::model::GetDocumentRequest::consistency_selector].
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_consistency_selector<
            T: Into<Option<crate::model::get_document_request::ConsistencySelector>>,
        >(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.consistency_selector = v.into();
            self
        }

        /// Sets the value of [consistency_selector][crate::model::GetDocumentRequest::consistency_selector]
        /// to hold a `Transaction`.
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_transaction<T: std::convert::Into<::bytes::Bytes>>(mut self, v: T) -> Self {
            self.0.request = self.0.request.set_transaction(v);
            self
        }

        /// Sets the value of [consistency_selector][crate::model::GetDocumentRequest::consistency_selector]
        /// to hold a `ReadTime`.
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_read_time<T: std::convert::Into<std::boxed::Box<wkt::Timestamp>>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request = self.0.request.set_read_time(v);
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for GetDocument {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::list_documents][crate::client::Firestore::list_documents] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::ListDocuments;
    /// # tokio_test::block_on(async {
    /// use gax::paginator::ItemPaginator;
    ///
    /// let builder = prepare_request_builder();
    /// let mut items = builder.by_item();
    /// while let Some(result) = items.next().await {
    ///   let item = result?;
    /// }
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> ListDocuments {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct ListDocuments(RequestBuilder<crate::model::ListDocumentsRequest>);

    impl ListDocuments {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::ListDocumentsRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::ListDocumentsResponse> {
            (*self.0.stub)
                .list_documents(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Streams each page in the collection.
        pub fn by_page(
            self,
        ) -> impl gax::paginator::Paginator<crate::model::ListDocumentsResponse, gax::error::Error>
        {
            use std::clone::Clone;
            let token = self.0.request.page_token.clone();
            let execute = move |token: String| {
                let mut builder = self.clone();
                builder.0.request = builder.0.request.set_page_token(token);
                builder.send()
            };
            gax::paginator::internal::new_paginator(token, execute)
        }

        /// Streams each item in the collection.
        pub fn by_item(
            self,
        ) -> impl gax::paginator::ItemPaginator<crate::model::ListDocumentsResponse, gax::error::Error>
        {
            use gax::paginator::Paginator;
            self.by_page().items()
        }

        /// Sets the value of [parent][crate::model::ListDocumentsRequest::parent].
        ///
        /// This is a **required** field for requests.
        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.parent = v.into();
            self
        }

        /// Sets the value of [collection_id][crate::model::ListDocumentsRequest::collection_id].
        pub fn set_collection_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.collection_id = v.into();
            self
        }

        /// Sets the value of [page_size][crate::model::ListDocumentsRequest::page_size].
        pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
            self.0.request.page_size = v.into();
            self
        }

        /// Sets the value of [page_token][crate::model::ListDocumentsRequest::page_token].
        pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.page_token = v.into();
            self
        }

        /// Sets the value of [order_by][crate::model::ListDocumentsRequest::order_by].
        pub fn set_order_by<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.order_by = v.into();
            self
        }

        /// Sets the value of [mask][crate::model::ListDocumentsRequest::mask].
        pub fn set_mask<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.mask = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [mask][crate::model::ListDocumentsRequest::mask].
        pub fn set_or_clear_mask<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.mask = v.map(|x| x.into());
            self
        }

        /// Sets the value of [show_missing][crate::model::ListDocumentsRequest::show_missing].
        pub fn set_show_missing<T: Into<bool>>(mut self, v: T) -> Self {
            self.0.request.show_missing = v.into();
            self
        }

        /// Sets the value of [consistency_selector][crate::model::ListDocumentsRequest::consistency_selector].
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_consistency_selector<
            T: Into<Option<crate::model::list_documents_request::ConsistencySelector>>,
        >(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.consistency_selector = v.into();
            self
        }

        /// Sets the value of [consistency_selector][crate::model::ListDocumentsRequest::consistency_selector]
        /// to hold a `Transaction`.
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_transaction<T: std::convert::Into<::bytes::Bytes>>(mut self, v: T) -> Self {
            self.0.request = self.0.request.set_transaction(v);
            self
        }

        /// Sets the value of [consistency_selector][crate::model::ListDocumentsRequest::consistency_selector]
        /// to hold a `ReadTime`.
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_read_time<T: std::convert::Into<std::boxed::Box<wkt::Timestamp>>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request = self.0.request.set_read_time(v);
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for ListDocuments {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::update_document][crate::client::Firestore::update_document] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::UpdateDocument;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> UpdateDocument {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct UpdateDocument(RequestBuilder<crate::model::UpdateDocumentRequest>);

    impl UpdateDocument {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::UpdateDocumentRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::Document> {
            (*self.0.stub)
                .update_document(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [document][crate::model::UpdateDocumentRequest::document].
        ///
        /// This is a **required** field for requests.
        pub fn set_document<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::Document>,
        {
            self.0.request.document = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [document][crate::model::UpdateDocumentRequest::document].
        ///
        /// This is a **required** field for requests.
        pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::Document>,
        {
            self.0.request.document = v.map(|x| x.into());
            self
        }

        /// Sets the value of [update_mask][crate::model::UpdateDocumentRequest::update_mask].
        pub fn set_update_mask<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.update_mask = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [update_mask][crate::model::UpdateDocumentRequest::update_mask].
        pub fn set_or_clear_update_mask<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.update_mask = v.map(|x| x.into());
            self
        }

        /// Sets the value of [mask][crate::model::UpdateDocumentRequest::mask].
        pub fn set_mask<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.mask = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [mask][crate::model::UpdateDocumentRequest::mask].
        pub fn set_or_clear_mask<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.mask = v.map(|x| x.into());
            self
        }

        /// Sets the value of [current_document][crate::model::UpdateDocumentRequest::current_document].
        pub fn set_current_document<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::Precondition>,
        {
            self.0.request.current_document = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [current_document][crate::model::UpdateDocumentRequest::current_document].
        pub fn set_or_clear_current_document<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::Precondition>,
        {
            self.0.request.current_document = v.map(|x| x.into());
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for UpdateDocument {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::delete_document][crate::client::Firestore::delete_document] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::DeleteDocument;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> DeleteDocument {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct DeleteDocument(RequestBuilder<crate::model::DeleteDocumentRequest>);

    impl DeleteDocument {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::DeleteDocumentRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<()> {
            (*self.0.stub)
                .delete_document(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [name][crate::model::DeleteDocumentRequest::name].
        ///
        /// This is a **required** field for requests.
        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.name = v.into();
            self
        }

        /// Sets the value of [current_document][crate::model::DeleteDocumentRequest::current_document].
        pub fn set_current_document<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::Precondition>,
        {
            self.0.request.current_document = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [current_document][crate::model::DeleteDocumentRequest::current_document].
        pub fn set_or_clear_current_document<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::Precondition>,
        {
            self.0.request.current_document = v.map(|x| x.into());
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for DeleteDocument {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::begin_transaction][crate::client::Firestore::begin_transaction] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::BeginTransaction;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> BeginTransaction {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct BeginTransaction(RequestBuilder<crate::model::BeginTransactionRequest>);

    impl BeginTransaction {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::BeginTransactionRequest>>(
            mut self,
            v: V,
        ) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::BeginTransactionResponse> {
            (*self.0.stub)
                .begin_transaction(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [database][crate::model::BeginTransactionRequest::database].
        ///
        /// This is a **required** field for requests.
        pub fn set_database<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.database = v.into();
            self
        }

        /// Sets the value of [options][crate::model::BeginTransactionRequest::options].
        pub fn set_options<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::TransactionOptions>,
        {
            self.0.request.options = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [options][crate::model::BeginTransactionRequest::options].
        pub fn set_or_clear_options<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::TransactionOptions>,
        {
            self.0.request.options = v.map(|x| x.into());
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for BeginTransaction {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::commit][crate::client::Firestore::commit] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::Commit;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> Commit {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct Commit(RequestBuilder<crate::model::CommitRequest>);

    impl Commit {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::CommitRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::CommitResponse> {
            (*self.0.stub)
                .commit(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [database][crate::model::CommitRequest::database].
        ///
        /// This is a **required** field for requests.
        pub fn set_database<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.database = v.into();
            self
        }

        /// Sets the value of [writes][crate::model::CommitRequest::writes].
        pub fn set_writes<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::Write>,
        {
            use std::iter::Iterator;
            self.0.request.writes = v.into_iter().map(|i| i.into()).collect();
            self
        }

        /// Sets the value of [transaction][crate::model::CommitRequest::transaction].
        pub fn set_transaction<T: Into<::bytes::Bytes>>(mut self, v: T) -> Self {
            self.0.request.transaction = v.into();
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for Commit {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::rollback][crate::client::Firestore::rollback] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::Rollback;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> Rollback {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct Rollback(RequestBuilder<crate::model::RollbackRequest>);

    impl Rollback {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::RollbackRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<()> {
            (*self.0.stub)
                .rollback(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [database][crate::model::RollbackRequest::database].
        ///
        /// This is a **required** field for requests.
        pub fn set_database<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.database = v.into();
            self
        }

        /// Sets the value of [transaction][crate::model::RollbackRequest::transaction].
        ///
        /// This is a **required** field for requests.
        pub fn set_transaction<T: Into<::bytes::Bytes>>(mut self, v: T) -> Self {
            self.0.request.transaction = v.into();
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for Rollback {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::partition_query][crate::client::Firestore::partition_query] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::PartitionQuery;
    /// # tokio_test::block_on(async {
    /// use gax::paginator::ItemPaginator;
    ///
    /// let builder = prepare_request_builder();
    /// let mut items = builder.by_item();
    /// while let Some(result) = items.next().await {
    ///   let item = result?;
    /// }
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> PartitionQuery {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct PartitionQuery(RequestBuilder<crate::model::PartitionQueryRequest>);

    impl PartitionQuery {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::PartitionQueryRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::PartitionQueryResponse> {
            (*self.0.stub)
                .partition_query(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Streams each page in the collection.
        pub fn by_page(
            self,
        ) -> impl gax::paginator::Paginator<crate::model::PartitionQueryResponse, gax::error::Error>
        {
            use std::clone::Clone;
            let token = self.0.request.page_token.clone();
            let execute = move |token: String| {
                let mut builder = self.clone();
                builder.0.request = builder.0.request.set_page_token(token);
                builder.send()
            };
            gax::paginator::internal::new_paginator(token, execute)
        }

        /// Streams each item in the collection.
        pub fn by_item(
            self,
        ) -> impl gax::paginator::ItemPaginator<crate::model::PartitionQueryResponse, gax::error::Error>
        {
            use gax::paginator::Paginator;
            self.by_page().items()
        }

        /// Sets the value of [parent][crate::model::PartitionQueryRequest::parent].
        ///
        /// This is a **required** field for requests.
        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.parent = v.into();
            self
        }

        /// Sets the value of [partition_count][crate::model::PartitionQueryRequest::partition_count].
        pub fn set_partition_count<T: Into<i64>>(mut self, v: T) -> Self {
            self.0.request.partition_count = v.into();
            self
        }

        /// Sets the value of [page_token][crate::model::PartitionQueryRequest::page_token].
        pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.page_token = v.into();
            self
        }

        /// Sets the value of [page_size][crate::model::PartitionQueryRequest::page_size].
        pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
            self.0.request.page_size = v.into();
            self
        }

        /// Sets the value of [query_type][crate::model::PartitionQueryRequest::query_type].
        ///
        /// Note that all the setters affecting `query_type` are
        /// mutually exclusive.
        pub fn set_query_type<T: Into<Option<crate::model::partition_query_request::QueryType>>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.query_type = v.into();
            self
        }

        /// Sets the value of [query_type][crate::model::PartitionQueryRequest::query_type]
        /// to hold a `StructuredQuery`.
        ///
        /// Note that all the setters affecting `query_type` are
        /// mutually exclusive.
        pub fn set_structured_query<
            T: std::convert::Into<std::boxed::Box<crate::model::StructuredQuery>>,
        >(
            mut self,
            v: T,
        ) -> Self {
            self.0.request = self.0.request.set_structured_query(v);
            self
        }

        /// Sets the value of [consistency_selector][crate::model::PartitionQueryRequest::consistency_selector].
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_consistency_selector<
            T: Into<Option<crate::model::partition_query_request::ConsistencySelector>>,
        >(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.consistency_selector = v.into();
            self
        }

        /// Sets the value of [consistency_selector][crate::model::PartitionQueryRequest::consistency_selector]
        /// to hold a `ReadTime`.
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_read_time<T: std::convert::Into<std::boxed::Box<wkt::Timestamp>>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request = self.0.request.set_read_time(v);
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for PartitionQuery {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::list_collection_ids][crate::client::Firestore::list_collection_ids] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::ListCollectionIds;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> ListCollectionIds {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct ListCollectionIds(RequestBuilder<crate::model::ListCollectionIdsRequest>);

    impl ListCollectionIds {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::ListCollectionIdsRequest>>(
            mut self,
            v: V,
        ) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::ListCollectionIdsResponse> {
            (*self.0.stub)
                .list_collection_ids(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [parent][crate::model::ListCollectionIdsRequest::parent].
        ///
        /// This is a **required** field for requests.
        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.parent = v.into();
            self
        }

        /// Sets the value of [page_size][crate::model::ListCollectionIdsRequest::page_size].
        pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
            self.0.request.page_size = v.into();
            self
        }

        /// Sets the value of [page_token][crate::model::ListCollectionIdsRequest::page_token].
        pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.page_token = v.into();
            self
        }

        /// Sets the value of [consistency_selector][crate::model::ListCollectionIdsRequest::consistency_selector].
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_consistency_selector<
            T: Into<Option<crate::model::list_collection_ids_request::ConsistencySelector>>,
        >(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.consistency_selector = v.into();
            self
        }

        /// Sets the value of [consistency_selector][crate::model::ListCollectionIdsRequest::consistency_selector]
        /// to hold a `ReadTime`.
        ///
        /// Note that all the setters affecting `consistency_selector` are
        /// mutually exclusive.
        pub fn set_read_time<T: std::convert::Into<std::boxed::Box<wkt::Timestamp>>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request = self.0.request.set_read_time(v);
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for ListCollectionIds {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::batch_write][crate::client::Firestore::batch_write] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::BatchWrite;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> BatchWrite {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct BatchWrite(RequestBuilder<crate::model::BatchWriteRequest>);

    impl BatchWrite {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::BatchWriteRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::BatchWriteResponse> {
            (*self.0.stub)
                .batch_write(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [database][crate::model::BatchWriteRequest::database].
        ///
        /// This is a **required** field for requests.
        pub fn set_database<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.database = v.into();
            self
        }

        /// Sets the value of [writes][crate::model::BatchWriteRequest::writes].
        pub fn set_writes<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::Write>,
        {
            use std::iter::Iterator;
            self.0.request.writes = v.into_iter().map(|i| i.into()).collect();
            self
        }

        /// Sets the value of [labels][crate::model::BatchWriteRequest::labels].
        pub fn set_labels<T, K, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = (K, V)>,
            K: std::convert::Into<std::string::String>,
            V: std::convert::Into<std::string::String>,
        {
            self.0.request.labels = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for BatchWrite {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Firestore::create_document][crate::client::Firestore::create_document] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_firestore::builder;
    /// use builder::firestore::CreateDocument;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> CreateDocument {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct CreateDocument(RequestBuilder<crate::model::CreateDocumentRequest>);

    impl CreateDocument {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Firestore>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::CreateDocumentRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::Document> {
            (*self.0.stub)
                .create_document(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [parent][crate::model::CreateDocumentRequest::parent].
        ///
        /// This is a **required** field for requests.
        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.parent = v.into();
            self
        }

        /// Sets the value of [collection_id][crate::model::CreateDocumentRequest::collection_id].
        ///
        /// This is a **required** field for requests.
        pub fn set_collection_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.collection_id = v.into();
            self
        }

        /// Sets the value of [document_id][crate::model::CreateDocumentRequest::document_id].
        pub fn set_document_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.document_id = v.into();
            self
        }

        /// Sets the value of [document][crate::model::CreateDocumentRequest::document].
        ///
        /// This is a **required** field for requests.
        pub fn set_document<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::Document>,
        {
            self.0.request.document = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [document][crate::model::CreateDocumentRequest::document].
        ///
        /// This is a **required** field for requests.
        pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::Document>,
        {
            self.0.request.document = v.map(|x| x.into());
            self
        }

        /// Sets the value of [mask][crate::model::CreateDocumentRequest::mask].
        pub fn set_mask<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.mask = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [mask][crate::model::CreateDocumentRequest::mask].
        pub fn set_or_clear_mask<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::DocumentMask>,
        {
            self.0.request.mask = v.map(|x| x.into());
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for CreateDocument {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }
}
